package net.akkz.dao.impl;

import java.util.ArrayList;

import net.akkz.dao.AnswerDao;
import net.akkz.dbFactory.Session;
import net.akkz.exception.BuildClassError;
import net.akkz.exception.SQLExcuteException;
import net.akkz.model.Answer;

public class AnswerDaoImpl implements AnswerDao
{

	@Override
	public void addAnswer(Session session, Answer answer) throws SQLExcuteException
	{
		String sql = "insert into answer(qid, answer, studentid) values(?, ?, ?)";

		Object[] values = new Object[3];
		values[0] = answer.getQid();
		values[1] = answer.getAnswer();
		values[2] = answer.getStudentid();
		
		session.excute(sql, values);
	}

	@Override
	public ArrayList<Answer> findAnswerByQuestionId(Session session, int questionId) throws SQLExcuteException, BuildClassError
	{
		String sql = "select * from answer where qid = ?";

		Object[] values = new Object[1];
		values[0] = questionId;
		
		return session.find(sql, values, Answer.class);
	}

	@Override
	public void deleteAnswer(Session session, int id) throws SQLExcuteException
	{
		String sql = "delete from answer where id = ?";

		Object[] values = new Object[1];
		values[0] = id;
		
		session.excute(sql, values);
	}

}
